package com.xbongbong.pro.businesstage.pojo;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.domain.entity.PaasStageEntity;
import com.xbongbong.paas.field.FieldAttrEntity;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/2/12 21:54
 * @since v1.0
 */
@Getter
@Setter
public class StageLaneViewColorWarningPojo {

    /**
     * 是否需要显示颜色预警
     */
    private boolean isShowStageWarningColor;

    /**
     * dataId到nowIntoStageTime时间戳的映射关系
     */
    private Map<Long, Long> dataId2NowIntoStageTimeMap;

    /**
     * nowIntoStageTime字段的attr
     */
    private String nowIntoStageTimeAttr;

    /**
     * 阶段信息
     */
    private PaasStageEntity stageEntity;

    public StageLaneViewColorWarningPojo() {
        this.isShowStageWarningColor = false;
        this.dataId2NowIntoStageTimeMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
    }

    public StageLaneViewColorWarningPojo(boolean isShowStageWarningColor, Map<Long, Long> dataId2NowIntoStageTimeMap, String nowIntoStageTimeAttr, PaasStageEntity stageEntity) {
        this.isShowStageWarningColor = isShowStageWarningColor;
        this.dataId2NowIntoStageTimeMap = dataId2NowIntoStageTimeMap;
        this.nowIntoStageTimeAttr = nowIntoStageTimeAttr;
        this.stageEntity = stageEntity;
    }

    /**
     * 泳道图中 判断 showList中是否有 nowIntoStageTimeAttr这个字段
     * @param showList
     */
    public void judgeIsShow4ShowList(List<FieldAttrEntity> showList){
        if (showList.stream().noneMatch(field -> Objects.equals(field.getAttr(), this.nowIntoStageTimeAttr))) {
            this.isShowStageWarningColor = false;
        }
    }
}
